package com.review.expert.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.review.common.annotation.Log;
import com.review.common.core.controller.BaseController;
import com.review.common.core.domain.AjaxResult;
import com.review.common.enums.BusinessType;
import com.review.expert.domain.expert;
import com.review.expert.service.IexpertService;
import com.review.common.utils.poi.ExcelUtil;
import com.review.common.core.page.TableDataInfo;

/**
 * 专家信息Controller
 * 
 * @author lls
 * @date 2022-03-13
 */
@RestController
@RequestMapping("/system/expert")
public class expertController extends BaseController
{
    @Autowired
    private IexpertService expertService;

    /**
     * 查询专家信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:expert:list')")
    @GetMapping("/list")
    public TableDataInfo list(expert expert)
    {
        startPage();
        List<expert> list = expertService.selectexpertList(expert);
        return getDataTable(list);
    }

    /**
     * 导出专家信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:expert:export')")
    @Log(title = "专家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, expert expert)
    {
        List<expert> list = expertService.selectexpertList(expert);
        ExcelUtil<expert> util = new ExcelUtil<expert>(expert.class);
        util.exportExcel(response, list, "专家信息数据");
    }

    /**
     * 获取专家信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:expert:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(expertService.selectexpertByUserId(userId));
    }

    /**
     * 新增专家信息
     */
    @PreAuthorize("@ss.hasPermi('system:expert:add')")
    @Log(title = "专家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody expert expert)
    {
        return toAjax(expertService.insertexpert(expert));
    }

    /**
     * 修改专家信息
     */
    @PreAuthorize("@ss.hasPermi('system:expert:edit')")
    @Log(title = "专家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody expert expert)
    {
        return toAjax(expertService.updateexpert(expert));
    }

    /**
     * 删除专家信息
     */
    @PreAuthorize("@ss.hasPermi('system:expert:remove')")
    @Log(title = "专家信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(expertService.deleteexpertByUserIds(userIds));
    }
}
